package com.gzy.cs5.model;

import com.gzy.cs5.lang.OrderStatus;
import java.util.ArrayList;
import java.util.List;
import java.time.LocalDateTime; // 新增导入

public class Order {
    private String orderId;
    private OrderStatus status;
    private List<Item> items;
    private double totalPrice;
    private LocalDateTime createTime; // 假设createTime字段存在
    private boolean isVIP; // 假设isVIP字段存在

    // 新增的构造函数
    public Order(String orderId, OrderStatus status) {
        this.orderId = orderId;
        this.status = status;
        this.items = new ArrayList<>();
        this.totalPrice = 0.0;
    }

    // 其他构造函数和方法
    public Order() {
    }

    public Order(String orderId, List<Item> items, OrderStatus status, double totalPrice, LocalDateTime createTime) {
        this.orderId = orderId;
        this.items = items;
        this.status = status;
        this.totalPrice = totalPrice;
        this.createTime = createTime;
    }

    public Order(String orderId, List<Item> items, OrderStatus status, double totalPrice, LocalDateTime createTime, boolean isVIP) {
        this.orderId = orderId;
        this.items = items;
        this.status = status;
        this.totalPrice = totalPrice;
        this.createTime = createTime;
        this.isVIP = isVIP;
    }

    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public OrderStatus getStatus() {
        return status;
    }

    public void setStatus(OrderStatus status) {
        this.status = status;
    }

    public List<Item> getItems() {
        return items;
    }

    public void setItems(List<Item> items) {
        this.items = items;
        this.totalPrice = calculateTotalPrice(items);
    }

    public double getTotalPrice() {
        return totalPrice;
    }

    public void setTotalPrice(double totalPrice) {
        this.totalPrice = totalPrice;
    }

    // 新增的getCreateTime方法
    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    private double calculateTotalPrice(List<Item> items) {
        double totalPrice = 0.0;
        for (Item item : items) {
            totalPrice += item.getPrice();
        }
        return totalPrice;
    }

    @Override
    public String toString() {
        return "Order{" +
                "orderId='" + orderId + '\'' +
                ", status=" + status +
                ", items=" + items +
                ", totalPrice=" + totalPrice +
                '}';
    }
}